package src.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class MyInputOutputStream {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream=new FileInputStream(new File("E:\\ofile.txt"));
        byte [] buf=new byte[1*1024];

        int bytes;
        int j=1;
        while ((bytes = fileInputStream.read(buf,0,buf.length))!=-1){
          for (int i=0;i<bytes;i++){
              System.out.print(Integer.toHexString(buf[i] & 0xff)+" ");
              if(j++%10==0){
                  System.out.println();
              }
          }
        }


        fileInputStream.read(buf);

        File ofile=new File("E:\\ofile.txt");
        if (!ofile.exists()){
            ofile.createNewFile();
        }
        FileOutputStream fileOutputStream=new FileOutputStream(ofile,true);
       // fileOutputStream.write(buf);
        byte [] ceshi="中国".getBytes("utf-8");
        fileOutputStream.write(ceshi);

        fileInputStream.close();
        fileOutputStream.close();
    }
}
